package idv.nightpig.lab02.web.interceptor;

import idv.nightpig.lab02.web.util.SessionKey;

import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

@Component
public class LoginInterceptor extends AbstractInterceptor {

    private static final long serialVersionUID = 1L;

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        String result = "login";
        Object user = invocation.getInvocationContext().getSession().get(SessionKey.USER.toString());
        if (user != null) {
            result = invocation.invoke();
        }
        return result;
    }

}
